home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
data
/
obs.js
< prev
next >
Wrap
Text File
|
2010-01-05
|
9KB
|
241 lines
// � 2005 The Weather Channel Interactive, Inc. All Rights Reserved.
// handle the obs data
oDataSources.Obs = function(){ };
oDataSources.Obs.prototype = new oDataSourcesStub;
function Observation() {}
Observation.inherits(oDataSourcesStub);
var Obs = new Observation();
Observation.prototype.setTooltip = function(){
try{
var sIcon = false;
var sLabel = false;
switch(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getToolTip().getType()){
case "icon":
sIcon = true;
break;
case "iconandlabel":
sIcon = true;
sLabel = true;
break;
case "label":
sLabel = true;
break;
}
// first, we make a tooltip object
var _tooltip = document.createElement("tooltip");
_tooltip.setAttribute("id", ToolbarContainers['CurrentCond'].getID() + ".Tooltip"); // and give it an id
var ttOuterVbox = document.createElement("vbox");
ttOuterVbox.setAttribute("class", "panelText");
_tooltip.appendChild(ttOuterVbox);
// now we make a pair of hboxs
var ttTopHbox = document.createElement("hbox");
ttOuterVbox.appendChild(ttTopHbox);
var ttBottomHbox = document.createElement("hbox");
ttOuterVbox.appendChild(ttBottomHbox);
// now we make a pair of vboxs
var ttTImageVbox = document.createElement("vbox");
ttTopHbox.appendChild(ttTImageVbox);
var ttTTextVbox = document.createElement("vbox");
ttTopHbox.appendChild(ttTTextVbox);
if(sIcon){
// the image goes in the first vbox
XULSimple.Image(ttTImageVbox, this.iconPath(this.Data['icon'], 'wx', 'large'), 64, 64);
}
if(sLabel){
var l = new oXUL.Label(ttTTextVbox, "As of: " + this.Data['lsup']);
l.Bold();
l.Make();
XULSimple.Label(ttTTextVbox, "in " + this.Data['dnam']);
XULSimple.Spacer(ttTTextVbox, 5);
var l = new oXUL.Label(ttTTextVbox, this.Data['t']);
l.Bold();
l.Make();
/*
XULSimple.Label(ttTTextVbox, "Temperature: " + this.Data['tmp'] + " " + Degrees + this.Data['ut']);
XULSimple.Label(ttTTextVbox, "Dew Point: " + this.Data['dewp'] + " " + Degrees + this.Data['ut']);
XULSimple.Label(ttTTextVbox, "Humidity: " + this.Data['hmid'] + "%");
XULSimple.Label(ttTTextVbox, "Visibility: " + this.Data['vis'] + " " + this.Data['ud']);
XULSimple.Label(ttTTextVbox, "Pressure: " + this.Data['bar.r'] + " " + this.Data['up'] + " and " + this.Data['bar.d']);
*
*/
XULSimple.Label(ttTTextVbox, "Temperature: " + this.Data['tmp'] + Degrees + this.Data['ut']);
XULSimple.Label(ttTTextVbox, "Dew Point: " + this.Data['dewp'] + Degrees + this.Data['ut']);
XULSimple.Label(ttTTextVbox, "Humidity: " + this.Data['hmid'] + "%");
XULSimple.Label(ttTTextVbox, "Visibility: " + this.Data['vis'] + " " + this.Data['ud']);
XULSimple.Label(ttTTextVbox, "Pressure: " + this.Data['bar.r'] + " " + this.Data['up'] + " and " + this.Data['bar.d']);
if(this.Data['wind.t'] == "CALM"){
XULSimple.Label(ttTTextVbox, "Winds: CALM");
}else{
XULSimple.Label(ttTTextVbox, "Winds: " + this.Data['wind.t'] + " at " + this.Data['wind.s'] + " " + this.Data['us']);
}
XULSimple.Spacer(ttTTextVbox, 5);
}
// now we make a pair of vboxs
var ttBImageVbox = document.createElement("vbox");
ttBottomHbox.appendChild(ttBImageVbox);
var ttBTextVbox = document.createElement("vbox");
ttBottomHbox.appendChild(ttBTextVbox);
if(sIcon){
// the image goes in the first vbox
XULSimple.Image(ttBImageVbox, this.iconPath(this.Data['moon.icon'], 'moon'), 64, 64);
}
if(sLabel){
var l = new oXUL.Label(ttBTextVbox, "Tonight:");
l.Bold();
l.Make();
XULSimple.Label(ttBTextVbox, "Sunset: " + this.Data['suns']);
XULSimple.Label(ttBTextVbox, "Moon Phase: " + this.Data['moon.t']);
}
_tooltip.setAttribute("noautohide", true);
_tooltip.setAttribute("align", "center");
}catch(e){
debugLog("catch in setTooltip: " + this.id + " " + e);
return(false);
}
try{
var p = document.getElementById(GlobalToolbarLocation)
var t = document.getElementById(ToolbarContainers['CurrentCond'].getID() + ".Tooltip");
if(p && t)
p.removeChild(t);
}catch(e){
debugLog("error removing tooltip: " + this.id + " " + e);
}
try{
document.getElementById(GlobalToolbarLocation).appendChild(_tooltip);
}catch(e){
debugLog("error appending tooltip: " + this.id + " " + e);
}
}
// parse an xml doc into our obs object
Observation.prototype.parseFunc = function(xmlDoc){
var configutil = new ConfigUtils();
try{
configutil.convertData(GlobalUserConfig, "Obs", xmlDoc);
}catch(e){
debug('error converting obs: ' + e);
}
this.oldData = this.Data;
this.Data = {}; // flush the Data hash
this.parseHeader(xmlDoc);
try{
// now we move on to the current conditions
var cc = xmlDoc.getElementsByTagName("cc")[0].childNodes;
var x = 0;
// loop through all the children under the cc node
for(x = 0; x < cc.length; x++){
try{
// if the nodes we find only have a value and no children, make them into variables
if((cc[x].childNodes.length == 1) && (typeof(cc[x].firstChild.nodeValue) == "string")){
this.Data[cc[x].nodeName] = cc[x].firstChild.nodeValue;
}else if(cc[x].childNodes.length > 1){
// if the child has more than one node under it, we deal with it a bit differently.
// we assume there will only be one more level below the current children so
// now we will make keys in this.Data[] names after the topchild.bottomchild like 'bar.r'
var child = cc[x].childNodes;
var y = 0;
for(y = 0; y < child.length; y++){
// if this is not a valid node name, skip it
if(child[y].nodeName == "#text"){
continue;
}
// otherwise, make a new entry in this.Data for it
if(typeof(child[y].firstChild.nodeValue) == "string"){
this.Data[cc[x].nodeName + "." + child[y].nodeName] = child[y].firstChild.nodeValue;
}
}
}
}catch(e){
debug('error parsing xml for obs: ' + e.message);
debugLog("error parsing obs data" + e);
}
}
}catch(e){
debugLog("catch in parse: " + this.id + " " + e);
}
this.run++;
this.setPanel();
this.Finish();
}
Observation.prototype.setPanel = function(){
try{
for(var p in this.PanelList){
var panel = this.PanelList[p];
// now we make a pair of hboxs
var panelHbox = document.createElement("hbox");
panelHbox.setAttribute("context", ToolbarContainers['CurrentCond'].getID() + ".Tooltip");
var url = this.getLink('localcity');
//panelHbox.setAttribute("onclick", "openLinkInNewTab('" + url + "');");
panelHbox.setAttribute("uri", url);
var panelText = "Now: " + this.Data['t'] + " and " + this.Data['tmp'] + Degrees + this.Data['ut'];
switch(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getType()){
case 'icon':
XULSimple.Image(panelHbox, this.iconPath(this.Data['icon'], 'wx', 'small'), 20, 20);
break;
case 'label':
XULSimple.Label(panelHbox, panelText);
break;
case 'iconandlabel':
XULSimple.Label(panelHbox, panelText);
XULSimple.Image(panelHbox, this.iconPath(this.Data['icon'], 'wx', 'small'), 20, 20);
break;
}
ToolbarContainers[panel].Show();
ToolbarContainers[panel].drawFromHbox(panelHbox);
panelHbox.addEventListener('click',interClickCurrent,true);
if(GlobalUserConfig.getAllProfiles().getDefaultProfile().getCurrentCond().getToolTip().getIsEnabled() == "true"){
ToolbarContainers[panel].enableTooltip();
this.setTooltip();
}else{
ToolbarContainers[panel].disableTooltip();
}
}
}catch(e){
debug("error setting obs panel: " + e);
debugLog("error creating Obs panels in Obs.setPanel " + e);
}
}